<template>
  <div class="list-container">
    <!-- 月劳务发放记录 -->
    <el-form class="search-panel" v-model="searchData" :inline="true">
      <!-- <el-form-item
        label-width="120px"
        class="search-time"
        label="考勤时间："
        prop="startToEnd"
      >
        <el-date-picker
          style="width: 250px"
          v-model="searchData.startToEnd"
          type="monthrange"
          range-separator="~"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="yyyy-MM"
        >
        </el-date-picker>
      </el-form-item> -->
      <el-form-item label="所属劳务公司" prop="corporation" label-width="130px">
        <el-select style="width:100%" v-model="params.corporation" clearable @clear="getTableListWorkflowApply()">
          <el-option v-for="item in corpList" :key="item.corporation"  :label="item.name" :value="item.corporation"/>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="getTableListWorkflowApply()">查询</el-button>
      </el-form-item>
    </el-form>
    <div class="table-panel">
        <!-- <el-row class="table-operate">
        <el-button @click="exportItems">
          导出 <i class="el-icon-upload2" />
        </el-button>
      </el-row> -->
      <el-table :data="totalData" style="width: 100%">
        <el-table-column
          prop="id"
          type="index"
          label="序号"
          width="60"
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="payDate"
          label="发放月份"
          align="center"
        >
          <template slot-scope="scope">
            <div>{{ scope.row.payDate }}</div>
          </template>
        </el-table-column>
        <el-table-column v-if="corpFlag" prop="serviceCorporationName" label="劳务公司名称" align="center">
        </el-table-column>
        <el-table-column prop="attendanceNum" label="提交人数" align="center">
        </el-table-column>
        <el-table-column
          prop="referenceMonthlyWageTotal"
          label="参考工资合计"
          align="center"
        >
          <template slot-scope="scope">
            <div>¥{{ scope.row.referenceMonthlyWageTotal }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="actualMonthWageTotal" label="实际工资合计" align="center">
          <template slot-scope="scope">
            <div>¥{{ scope.row.actualMonthWageTotal }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="issuedMonthlyWage" label="已发放金额" align="center">
          <template slot-scope="scope">
            <div>¥{{ scope.row.issuedMonthlyWage }}</div>
          </template>
        </el-table-column>
        <el-table-column
          prop="unissuedMonthlyWage"
          label="未发放金额"
          align="center"
        >
          <template slot-scope="scope">
            <div>¥{{ scope.row.unissuedMonthlyWage }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="payDate" label="发放时间" align="center"/>
        <el-table-column prop="status" label="审核状态" align="center"/>
        <el-table-column
          prop="operation"
          label="操作"
          align="center"
        >
          <template slot-scope="scope">
            <el-button
              @click="checkedRow(scope.row)"
              type="text"
              icon="el-icon-search"
              >查看</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <el-row class="page">
        <!-- <div class="page-tag">
          共{{ Math.ceil(total / pageSize) }}页/{{ total }}条数据
        </div>
        <el-pagination
          background
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page.sync="currentPage"
          :page-sizes="[10, 20, 50]"
          :page-size="pageSize"
          layout="sizes, prev, pager, next, jumper"
          :total="total"
        >
        </el-pagination> -->
        <pagination
          background
          v-show="total>0"
          :total="total"
          :page.sync="params.pageNum"
          :limit.sync="params.pageSize"
          @pagination="getTableListWorkflowApply"
        />
      </el-row>
    </div>
  </div>
</template>

<script>
import { monthWageList } from "@/api/monthlyWage";
import workflowApi from '@/api/workflow/workFlow'
import corpApi from '@/api/corp.js'
export default {
  data() {
    return {
      corpFlag: true,
      searchData: {
        startToend: null,
      },
      totalData: [],
      corpList:[],
      params:{
        pageNum: 1,
        pageSize: 10,
        isAsc: 'desc',
        // workflowType:'',
        companyName: ''
      },
      total: 0,
      pageSize: 10,
      currentPage: 1,
    };
  },
  created(){
    //this.getTableData()
    let companyName = localStorage.getItem('companyName')
    if(companyName == null || undefined) {
      this.corpFlag = true
    } else {
      this.corpFlag = false
    }
    this.params.companyName = companyName
    this.getTableListWorkflowApply()
    this.getCorpList()
  },
  methods: {
    // getTableData() {
    //   let data = {
    //     pageSize:this.pageSize,
    //     currentPage:this.currentPage,
    //     startDate:this.searchData.startDate,
    //     endDate:this.searchData.endDate
    //   }
    //   monthWageList(data).then((res)=>{
    //     this.tableData = res.data.data.records
    //     this.total = res.data.data.total
    //     console.log(res);
    //   });
    // },
    getTableListWorkflowApply() {
      this.params.workflowType = '劳务代发审批'
      workflowApi.getTableListWorkflowApply(this.params).then(res => {
        // console.log(res)
        var tableData = []
        let that = this
        if(res.data){
          res.data.forEach(function(item, index) {
            let data=item.attachInfo.split("*")
            tableData.push({
              payDate:data[0],
              serviceCorporationName:data[1],
              attendanceNum:data[2],
              referenceMonthlyWageTotal:data[3],
              actualMonthWageTotal:data[4],
              issuedMonthlyWage:data[5],
              unissuedMonthlyWage:data[6],
              projectId:data[7],
              status:that.convertStatus(item.applyStatus),
              workflowApplyId:item.applyId,
              personIds : item.personIds
              }
            )
          })
        }
        this.totalData = tableData
        this.total = this.totalData.length
      })
    },
    onSubmit() {
      this.searchData.startDate = this.searchData.startToEnd[0]
      this.searchData.endDate = this.searchData.startToEnd[1]
      this.getTableData()
      console.log(this.searchData);
    },
    // 导出
    exportItems(){

    },
    // 查看
    checkedRow(res) {
      // console.log("-----------------")
      // console.log(res)
      this.$router.push({path:'/agency/issuanceRecord',query:{workflowApplyId:res.workflowApplyId,date:res.attendanceTime,personIds:res.personIds}})
    },
    // 发放
    issuanceRow(date) {},
    handleSizeChange(val) {},
    handleCurrentChange(val) {},
    convertStatus(status){
      let newStatus = "未知"
      switch (status){
        case '1': newStatus = "待审核";break;
        case '2': newStatus = "审核中";break;
        case '3': newStatus = "已审核";break;
        case '4': newStatus = "已驳回";break;
        case '5': newStatus = "已撤回";break;
      }
      return newStatus
    },
    getCorpList() {
      // var treeData = this.treeData
      corpApi.listByProjectId().then(res => {
          let date = res.data.data.records
          let data = []
          date.forEach(function(item,index) {
              data.push({name: item.name, corporation: item.serviceCorporationId+''})
              // treeData.push({corpName: item.name, companyId: item.serviceCorporationId+''})
          })
          this.corpList = data
          // this.treeData = treeData
      })

    }
  },
};
</script>
